import { BaseWindow } from "../../../component/window/BaseWindow";
import { SBossFieldPlayerScore } from "../../../../Message/Public/SBossFieldPlayerScore";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { TilePanel } from "../equipment/TilePanel";
import { BossFieldScoreCellRenderer } from "./cell/BossFieldScoreCellRenderer";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { PageSelecter } from "../common/pageSelect/PageSelecter";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { BossFieldTopData } from "./cellData/BossFieldTopData";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { GButton } from "../../../../com/mui/controls/GButton";
import { Vector } from "../../../../__AS3__/vec/Vector";
type int = number;
//class BossFieldTopWindow
    
    export  class BossFieldTopWindow extends BaseWindow
    {
        constructor()
        {
            super();
            this._vcPlayerScores = new Vector.<SBossFieldPlayerScore>();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this.initBase();
            this.createChild();
            this.addListeners();
            return;
        }

        /* internal  */initBase(): void
        {
            titleHeight = 26;
            setSize(750, 450);
            title = Language.getString(41605);
            return;
        }

        /* internal  */createChild(): void
        {
            this._bg = ObjCreate.createBg(17, 38, 715, 362, this, "WindowCenterB");
            this._titleContainer = new Object /* flash.display.Sprite */();
            this._titleContainer.x = 30;
            this._titleContainer.y = 50;
            this.addChild(this._titleContainer);
            this.createTitle();
            this.createList();
            this.createBottom();
            return;
        }

        /* internal  */createList(): void
        {
            this._topTilePanel = new TilePanel();
            this._topTilePanel.setSize(700, 310);
            this._topTilePanel.rowHeight = 31;
            this._topTilePanel.columnWidth = 700;
            this._topTilePanel.setStyle("cellRenderer", BossFieldScoreCellRenderer);
            this._topTilePanel.x = 30;
            this._topTilePanel.y = 72;
            this.addChild(this._topTilePanel);
            return;
        }

        /* internal  */createTitle(): void
        {
            var loc1=new GTextFormat(FontUtil.songtiName, 12, 11661311);
            loc1.align = flash.text.TextFormatAlign.CENTER;
            var loc2=ObjCreate.createTextField(Language.getString(41606), 0, 0, 50, 20, this._titleContainer, loc1);
            var loc3=ObjCreate.createTextField(Language.getString(41607), 45, 0, 180, 20, this._titleContainer, loc1);
            var loc4=ObjCreate.createTextField(Language.getString(41608), 210, 0, 60, 20, this._titleContainer, loc1);
            var loc5=ObjCreate.createTextField(Language.getString(41609), 270, 0, 60, 20, this._titleContainer, loc1);
            var loc6=ObjCreate.createTextField(Language.getString(41610), 330, 0, 60, 20, this._titleContainer, loc1);
            var loc7=ObjCreate.createTextField(Language.getString(41698), 390, 0, 60, 20, this._titleContainer, loc1);
            var loc8=ObjCreate.createTextField(Language.getString(41699), 450, 0, 60, 20, this._titleContainer, loc1);
            var loc9=ObjCreate.createTextField(Language.getString(41707), 510, 0, 60, 20, this._titleContainer, loc1);
            var loc10=ObjCreate.createTextField(Language.getString(41708), 570, 0, 60, 20, this._titleContainer, loc1);
            var loc11=ObjCreate.createTextField(Language.getString(41709), 630, 0, 60, 20, this._titleContainer, loc1);
            return;
        }

        /* internal  */createBottom(): void
        {
            this._spBottomPart = new Object /* flash.display.Sprite */();
            this._spBottomPart.x = 20;
            this._spBottomPart.y = 405;
            this.addChild(this._spBottomPart);
            this._pageSelecter = new PageSelecter();
            this._pageSelecter.mode = PageSelecter.InputMode;
            this._pageSelecter.x = 200;
            this._pageSelecter.y = 5;
            this._spBottomPart.addChild(this._pageSelecter);
            this._btnLeave = ObjCreate.createGButton(Language.getString(41617), 525, 4, 59, 22);
            return;
        }

        /* internal  */addListeners(): void
        {
            this._btnLeave.addEventListener(flash.events.MouseEvent.CLICK, this.onLeaveClick);
            this._pageSelecter.addEventListener(flash.events.Event.CHANGE, this.pageChangeHandler);
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStage);
            return;
        }

        /* internal  */onLeaveClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.BossFieldRequestLeaveAffirm));
            return;
        }

        /* internal  */pageChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this.refreshList();
            return;
        }

        /* internal  */onAddToStage(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.BossFieldRequestResult));
            return;
        }

        /* internal  */getDataProvider(): DataProvider
        {
            var loc1=new Array<any>();
            var loc2=(this._pageSelecter.currentPage - 1) * this.pageSize;
            var loc3=Math.min(this._pageSelecter.currentPage * this.pageSize, this._vcPlayerScores.length);
            var loc4=loc2;
            while (loc4 < loc3) 
            {
                loc1.push(new BossFieldTopData(loc4 + 1, this._vcPlayerScores[loc4]));
                ++loc4;
            }
            return new DataProvider(loc1);
        }

        /* internal  */refreshList(): void
        {
            this._topTilePanel.dataProvider = this.getDataProvider();
            return;
        }

        public refreshScores(arg1: Vector.<SBossFieldPlayerScore>): void
        {
            this._vcPlayerScores = arg1;
            this._pageSelecter.maxPage = Math.ceil(arg1.length / this.pageSize);
            this._pageSelecter.currentPage = 1;
            this.refreshList();
            this.show();
            return;
        }

        public showLeaveBtn(): void
        {
            this._spBottomPart.addChild(this._btnLeave);
            return;
        }

        public static hasInstance(): Boolean
        {
            return !(BossFieldTopWindow._instance == null);
        }

        public static get instance(): BossFieldTopWindow
        {
            if (!BossFieldTopWindow._instance) 
            {
                BossFieldTopWindow._instance = new BossFieldTopWindow();
            }
            return BossFieldTopWindow._instance;
        }

        /* internal */ /* const */pageSize: int=10;

        /* internal */ /* var */_titleContainer: Object /* flash.display.Sprite */;

        /* internal */ /* var */_bg: ScaleBitmap;

        /* internal */ /* var */_topTilePanel: TilePanel;

        /* internal */ /* var */_spBottomPart: Object /* flash.display.Sprite */;

        /* internal */ /* var */_btnMyFight: GButton;

        /* internal */ /* var */_pageSelecter: PageSelecter;

        /* internal */ /* var */_btnLeave: GButton;

        /* internal */ /* var */_vcPlayerScores: Vector.<SBossFieldPlayerScore>;

        /* internal */ static /* var */_instance: BossFieldTopWindow;
    }
